package vsvm.data.filter.ranking;

import java.util.ArrayList;
import java.util.HashSet;

public abstract class AbstractSupervisedRanking extends AbstractRankingFilter {
	/**
	 * 
	 */
	private static final long serialVersionUID = 100L;
	private ArrayList<double[]> subset;
	private ArrayList<ArrayList<double[]>> set;

	protected void generateSubsets(){
		int numberOfObjects = dataModel.getVectorCount();
        set = new ArrayList<ArrayList<double[]>>();
        HashSet<Double> setLabel = new HashSet<Double>();
        
		for(int i = 0; i < numberOfObjects; i++){
			double classLabel = dataModel.getClass(i);			
						
			if(!setLabel.contains(dataModel.getClass(i))){
                setLabel.add(dataModel.getClass(i));
                subset = new ArrayList<double[]>();
                for(int j = 0; j < numberOfObjects; j++){
                	if(classLabel == dataModel.getClass(j)){
                		subset.add(dataModel.getVector(j));                		
                	}                	
                } 
                set.add(subset);
            }
		}
	}
	
	protected int classLength(int i){
		return (set.get(i)).size();
	}
	
	protected int numberOfClasses(){
		return set.size();
	}
	
	
	
	protected double[] classFeatureValues(int classNumber, int featureNumber){
		int size = classLength(classNumber);
		double[] values = new double[size];
		for(int i = 0; i < size; i++){
			values[i] = set.get(classNumber).get(i)[featureNumber];
		}				
		return values;
	}

}
